<?php
namespace Admin\Controller;
use app\mobile\controller\Base;
use Think\Controller;

/**
 * 用户信息控制器
 * Class MemberController
 * @package Admin\Controller
 */
class MemberController extends BaseController{
    /**
     * 添加用户
     */
    public function addMember()
    {
        if (I("post.name")) {
            $member = M('userbase');
            $data = $member->create();
            $data = array(
                'name'=>$data['name'],
                'basename'=>$data['basename'],
                'pwd'=>$data['pwd'] = md5($data['pwd']),
                'email'=>$data['email'],
                'phone'=>$data['phone'],
                'qq'=>$data['qq'],
                'status'=>'0',
                'imagepath'=>$data['imagepath'],
                'pid'=>'',
                'update_time'=>date("Y-m-d H:i:s",time()),
                'create_time'=>date("Y-m-d H:i:s",time()),
                'last_login_time'=>'',
                'tips'=>'dx'
            );
            $res = $member->add($data);
            if ($res) {
                //记录操作到日志
                $action_name = "新增".I("post.name")."用户";
                $time = date("Y-m-d H:i:s", time());
                parent::rizhi($action_name, $time);

                    $this->ajaxReturn(['info' => '新增成功', 'status' => 1, 'url' => U('Member/memberList')]);
                } else {
                    $this->ajaxReturn(['info' => '新增失败', 'status' => 0, 'url' => U('Member/addMember')]);
                }
            } else {
                $this->display();
            }
    }


    /**
     * 用户列表
     */
    public function memberList()
    {
            //实例化Memebr
            $member = M('userbase');
        $this->error('lkskjfkdlkfjl','#');
            // 导入分页类
            import('Org.Util.Page');

            //查询满足满足条件的总记录条数
            $count = $member->count();

            //实例化分页类 传入总记录数和每页显示的记录数
            $Page = new \Think\Page($count, 10);
            $Page->rollPage=5;
            //分页显示输出
            $show = $Page->show();

            $data = $member->order('create_time desc')->limit($Page->firstRow . ',' . $Page->listRows)->select();
            $this->assign('memberlist', $data);
            $this->assign('page', $show);
            $this->display();
    }
}

